module.exports = function ($scope, $state, $resource, $modal, toaster) {
	$scope.myKeyup = function (e) {
		//IE 编码包含在window.event.keyCode中，Firefox或Safari 包含在event.which中
		var keycode = window.event ? e.keyCode : e.which;
		if (keycode == 13) {
			$scope.loadlist();
		}
	};
	$scope.pageInfo = {};
	$scope.pageInfo.pageNo = 1;		//当前页码
	$scope.pageInfo.pageSize = 10;	//每页显示几条
	$scope.pageInfo.totalItems = 0;	//总条数
	//列表
	$scope.loadlist = function () {
		$resource('/api/as/mc/shopproduct/findCardsList', {}, {}).save($scope.pageInfo, function (res) {
			if (res.errcode === 0) {
				$scope.beanList = res.data.results;
				$scope.pageInfo.totalItems = res.data.totalRecord;
			} else {
				toaster.error({ title: '', body: res.errmsg });
			}
		});
		// $resource('/api/as/mc/shopproduct/findMyProductNoPageList', {}, {}).save({}, function (res) {
		// 	if (res.errcode === 0) {
		// 		$scope.ProductList = res.data;
		// 	} else {
		// 		toaster.error({ title: '', body: res.errmsg });
		// 	}
		// });
	}

	$scope.loadlist();

	

	// //发送
  //   $scope.add = function (bean) {
	// 		$resource('/api/as/mc/shopproduct/insertCardsProduct', {}, {}).save(bean, function (res) {
	// 			if (res.errcode === 0) {
	// 				$scope.loadlist();
	// 			} else {
	// 				toaster.error({ title: '', body: res.errmsg });
	// 			}
	// 		});
	// }

 	//添加or修改
   $scope.add = function(info) {
		var modalInstance = $modal.open({
			template: require('../views/discountcardinfo.html'),
			controller: 'discountcardinfo',
			size: 'lg',
			resolve: {
				item : function () {
					return info;
        },
				flag : function () {
					return info == 1;
				}
			}
		});
		//关闭模态框刷新页面
		modalInstance.result.then(function() {
			$scope.loadlist();
		});
  }
  $scope.update = function(info) {
		var modalInstance = $modal.open({
			template: require('../views/discountcardinfo.html'),
			controller: 'discountcardinfo',
			size: 'lg',
			resolve: {
				item : function () {
					return info;
        },
				flag : function () {
					return info == '';
				}
			}
		});
		//关闭模态框刷新页面
		modalInstance.result.then(function() {
			$scope.loadlist();
		});
	}
	//删除
	$scope.delete = function (bean) {
		if (confirm('确认删除此条记录吗？') == true) {
			$resource('/api/as/mc/shopproduct/updateCardsdel', {}, {}).save(bean, function (res) {
				if (res.errcode === 0) {
					$scope.loadlist();
				} else {
					toaster.error({ title: '', body: res.errmsg });
				}
			});
		}
	}

};